package com.ym.pms.dao;

import com.ym.pms.dao.provider.SearchProvider;
import com.ym.pms.model.Contract;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author lmt
 * @since 2020-12-23
 */
@Repository
public interface ContractMapper extends BaseMapper<Contract> {
    @Results(id = "contract", value =
            {
                    @Result(column = "co_id", property = "coId"),
                    @Result(column = "co_uid", property = "coUid"),
                    @Result(column = "co_PAName", property = "coPAName"),
                    @Result(column = "co_PBName", property = "coPBName"),
                    @Result(column = "co_PAPNo", property = "coPAPNo"),
                    @Result(column = "co_PBPNo", property = "coPBPNo"),
                    @Result(column = "co_ItId", property = "coItId"),
                    @Result(column = "co_BuCoding", property = "coBuCoding"),
                    @Result(column = "co_suCoding", property = "coSuCoding"),
                    @Result(column = "co_RmCoding", property = "coRmCoding"),
                    @Result(column = "co_BkCoding", property = "coBkCoding"),
                    @Result(column = "co_rent", property = "coRent"),
                    @Result(column = "co_RCTime", property = "coRCTime"),
                    @Result(column = "co_PCosts", property = "coPCosts"),
                    @Result(column = "co_Gtime", property = "coGtime"),
                    @Result(column = "co_deposit", property = "coDeposit"),
                    @Result(column = "co_RDtime", property = "coRDtime"),
                    @Result(column = "co_BETime", property = "coBETime"),
                    @Result(column = "co_Mtime", property = "coMtime"),
                    @Result(column = "co_CStatus", property = "coCStatus"),
                    @Result(column = "co_TTime", property = "coTTime"),
                    @Result(column = "co_RFT", property = "coRFT"),
                    @Result(column = "co_LD", property = "coLD"),
                    @Result(column = "co_remark", property = "coRemark")
            })
    @Select("select * from contract")
    List<Contract> queryAll();

    @ResultMap("contract")
    @Insert("insert into contract(co_id,co_PAName,co_PAPNo,co_ItId,co_BuCoding,co_suCoding,co_RmCoding,co_BkCoding,co_rent,co_PCosts,co_Gtime,co_deposit,co_RDtime,co_BETime,co_Mtime,co_CStatus,co_LD,co_remark,co_pdf)\n" +
            " VALUES (0,#{coPAName},#{coPAPNo},#{coItId},#{coBuCoding},#{coSuCoding},#{coRmCoding},#{coBkCoding},#{coRent},#{coPCosts},#{coGtime},#{coDeposit},#{coRDtime},#{coBETime},#{coMtime},2,#{coLD},#{coRemark},#{coPdf})")
    void addInitInfo(Contract contract);

    @Delete("delete from contract where co_id=#{contractId}")
    void deleteInfo(Integer contractId);

    @Update("update contract set co_CStatus=3,co_RFT=#{coRFT},co_TTime=#{nowDate} where co_id=#{id}")
    void updateInfo(@Param("id") Integer id, @Param("coRFT") String coRFT,@Param("nowDate") Date nowDate);

    @Update("update contract set co_PBName=#{coPBName},co_PBPNo=#{coPBPNo},co_CStatus=1 where co_id=#{id}")
    void saveInfo(@Param("id") Integer id, @Param("coPBName") String coPBName, @Param("coPBPNo") String coPBPNo);

    @Select("select * from contract where co_id=#{id}")
    Contract queryOne(Integer id);

    @ResultMap("contract")
    @SelectProvider(type= com.ym.pms.dao.provider.SearchProvider.class, method="search")
    List<Contract> search(Contract con);

    @Update("update contract set co_CStatus=3,co_RFT='合同到期' where co_id=#{id}")
    void updateStatus(Integer id);

    @Update("update contract set co_photo=#{path} where co_id=#{id}")
    void addPhoto(@Param("id") Integer id,@Param("path") String path);
}
